package cn.tedu.csmall.cart.webapi.config;

import cn.tedu.csmall.cart.webapi.interceptor.DemoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    // 将拦截器对象从Spring容器中获取出来
    @Autowired
    private DemoInterceptor demoInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 配置哪个拦截器对象拦截哪个路径
        registry.addInterceptor(demoInterceptor)
                // 设置拦截路径,支持统配,例如 /base/cart/*
                .addPathPatterns("/base/cart/add");
    }
}
